{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "10675e91",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sqlalchemy import create_engine\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import tushare as ts\n",
    "import os\n",
    "from datetime import datetime\n",
    "from datetime import timedelta\n",
    "import time\n",
    "from tqdm.notebook import tqdm\n",
    "import matplotlib.pyplot as plt\n",
    "import akshare as ak\n",
    "import json\n",
    "from loguru import logger\n",
    "import statsmodels.api as sm\n",
    "from statsmodels.regression.rolling import RollingOLS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "5e5d9c99",
   "metadata": {},
   "outputs": [],
   "source": [
    "folder_path = 'data/'\n",
    "\n",
    "file_path = f'sqlite:////{folder_path}'\n",
    "\n",
    "token = 'd942e6ff0e981f76aaa544f84405583e0c2129a8c82213637835a099'\n",
    "pro = ts.pro_api(token)\n",
    "\n",
    "folder = 'data/'\n",
    "start_date = '20100101'\n",
    "\n",
    "today = datetime.strftime(datetime.now(),'%Y%m%d')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d3575edc",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 获取所有股票上市日期的数据\n",
    "dd_stocks1 = pro.stock_basic(list_status='L')\n",
    "dd_stocks2 = pro.stock_basic(list_status='D')\n",
    "dd_stocks3 = pro.stock_basic(list_status='P')\n",
    "dd_stocks = pd.concat([dd_stocks1,dd_stocks2,dd_stocks3]).reset_index(drop=True)\n",
    "dd_stocks = dd_stocks[dd_stocks['ts_code'].apply(lambda x:x.split('.')[1] in ['SZ','SH'])].reset_index(drop=True)\n",
    "dd_stocks = dd_stocks.sort_values(by=['ts_code'],ascending=False).reset_index(drop=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "898bceba",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ts_code</th>\n",
       "      <th>symbol</th>\n",
       "      <th>name</th>\n",
       "      <th>area</th>\n",
       "      <th>industry</th>\n",
       "      <th>market</th>\n",
       "      <th>list_date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>T00018.SH</td>\n",
       "      <td>T00018</td>\n",
       "      <td>上港集箱(退)</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>20000719</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>689009.SH</td>\n",
       "      <td>689009</td>\n",
       "      <td>九号公司-WD</td>\n",
       "      <td>北京</td>\n",
       "      <td>摩托车</td>\n",
       "      <td>CDR</td>\n",
       "      <td>20201029</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>688981.SH</td>\n",
       "      <td>688981</td>\n",
       "      <td>中芯国际</td>\n",
       "      <td>上海</td>\n",
       "      <td>半导体</td>\n",
       "      <td>科创板</td>\n",
       "      <td>20200716</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>688819.SH</td>\n",
       "      <td>688819</td>\n",
       "      <td>天能股份</td>\n",
       "      <td>浙江</td>\n",
       "      <td>电气设备</td>\n",
       "      <td>科创板</td>\n",
       "      <td>20210118</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>688800.SH</td>\n",
       "      <td>688800</td>\n",
       "      <td>瑞可达</td>\n",
       "      <td>江苏</td>\n",
       "      <td>元器件</td>\n",
       "      <td>科创板</td>\n",
       "      <td>20210722</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4666</th>\n",
       "      <td>000005.SZ</td>\n",
       "      <td>000005</td>\n",
       "      <td>ST星源</td>\n",
       "      <td>深圳</td>\n",
       "      <td>环境保护</td>\n",
       "      <td>主板</td>\n",
       "      <td>19901210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4667</th>\n",
       "      <td>000004.SZ</td>\n",
       "      <td>000004</td>\n",
       "      <td>国华网安</td>\n",
       "      <td>深圳</td>\n",
       "      <td>软件服务</td>\n",
       "      <td>主板</td>\n",
       "      <td>19910114</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4668</th>\n",
       "      <td>000003.SZ</td>\n",
       "      <td>000003</td>\n",
       "      <td>PT金田A(退)</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>主板</td>\n",
       "      <td>19910703</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4669</th>\n",
       "      <td>000002.SZ</td>\n",
       "      <td>000002</td>\n",
       "      <td>万科A</td>\n",
       "      <td>深圳</td>\n",
       "      <td>全国地产</td>\n",
       "      <td>主板</td>\n",
       "      <td>19910129</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4670</th>\n",
       "      <td>000001.SZ</td>\n",
       "      <td>000001</td>\n",
       "      <td>平安银行</td>\n",
       "      <td>深圳</td>\n",
       "      <td>银行</td>\n",
       "      <td>主板</td>\n",
       "      <td>19910403</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4671 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        ts_code  symbol      name  area industry market list_date\n",
       "0     T00018.SH  T00018   上港集箱(退)  None     None   None  20000719\n",
       "1     689009.SH  689009   九号公司-WD    北京      摩托车    CDR  20201029\n",
       "2     688981.SH  688981      中芯国际    上海      半导体    科创板  20200716\n",
       "3     688819.SH  688819      天能股份    浙江     电气设备    科创板  20210118\n",
       "4     688800.SH  688800       瑞可达    江苏      元器件    科创板  20210722\n",
       "...         ...     ...       ...   ...      ...    ...       ...\n",
       "4666  000005.SZ  000005      ST星源    深圳     环境保护     主板  19901210\n",
       "4667  000004.SZ  000004      国华网安    深圳     软件服务     主板  19910114\n",
       "4668  000003.SZ  000003  PT金田A(退)  None     None     主板  19910703\n",
       "4669  000002.SZ  000002       万科A    深圳     全国地产     主板  19910129\n",
       "4670  000001.SZ  000001      平安银行    深圳       银行     主板  19910403\n",
       "\n",
       "[4671 rows x 7 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dd_stocks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8c7aac52",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4b0508a6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a5690560",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "ts_code = '601012.SH'\n",
    "\n",
    "database_name='daily_kline.db'\n",
    "engine = create_engine(file_path+database_name)\n",
    "table_name = 'daily_kline'\n",
    "dd_kline = pd.read_sql(f\"select * from {table_name} where ts_code='{ts_code}'\",engine)\n",
    "\n",
    "database_name='daily_adj.db'\n",
    "engine = create_engine(file_path+database_name)\n",
    "table_name = 'daily_adj'\n",
    "dd_adj = pd.read_sql(f\"select * from {table_name} where ts_code='{ts_code}'\",engine)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "2d56efa7",
   "metadata": {},
   "outputs": [],
   "source": [
    "database_name='dailybasic.db'\n",
    "engine = create_engine(file_path+database_name)\n",
    "table_name = 'dailybasic'\n",
    "dd_dailybasic = pd.read_sql(f\"select * from {table_name} where ts_code='{ts_code}'\",engine)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6b5a51c8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "3c64a12c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>index</th>\n",
       "      <th>ts_code</th>\n",
       "      <th>trade_date</th>\n",
       "      <th>close</th>\n",
       "      <th>turnover_rate</th>\n",
       "      <th>turnover_rate_f</th>\n",
       "      <th>volume_ratio</th>\n",
       "      <th>pe</th>\n",
       "      <th>pe_ttm</th>\n",
       "      <th>pb</th>\n",
       "      <th>ps</th>\n",
       "      <th>ps_ttm</th>\n",
       "      <th>dv_ratio</th>\n",
       "      <th>dv_ttm</th>\n",
       "      <th>total_share</th>\n",
       "      <th>float_share</th>\n",
       "      <th>free_share</th>\n",
       "      <th>total_mv</th>\n",
       "      <th>circ_mv</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1236</td>\n",
       "      <td>601012.SH</td>\n",
       "      <td>20120411</td>\n",
       "      <td>19.75</td>\n",
       "      <td>23.6622</td>\n",
       "      <td>23.6622</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20.7976</td>\n",
       "      <td>20.7976</td>\n",
       "      <td>1.9818</td>\n",
       "      <td>2.9281</td>\n",
       "      <td>2.9281</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>29918.0000</td>\n",
       "      <td>6000.0000</td>\n",
       "      <td>6000.0000</td>\n",
       "      <td>5.908805e+05</td>\n",
       "      <td>1.185000e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1223</td>\n",
       "      <td>601012.SH</td>\n",
       "      <td>20120412</td>\n",
       "      <td>19.47</td>\n",
       "      <td>13.9525</td>\n",
       "      <td>13.9525</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20.5027</td>\n",
       "      <td>20.5027</td>\n",
       "      <td>1.9537</td>\n",
       "      <td>2.8866</td>\n",
       "      <td>2.8866</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>29918.0000</td>\n",
       "      <td>6000.0000</td>\n",
       "      <td>6000.0000</td>\n",
       "      <td>5.825035e+05</td>\n",
       "      <td>1.168200e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1229</td>\n",
       "      <td>601012.SH</td>\n",
       "      <td>20120413</td>\n",
       "      <td>19.74</td>\n",
       "      <td>11.3160</td>\n",
       "      <td>11.3160</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20.7870</td>\n",
       "      <td>20.7870</td>\n",
       "      <td>1.9808</td>\n",
       "      <td>2.9266</td>\n",
       "      <td>2.9266</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>29918.0000</td>\n",
       "      <td>6000.0000</td>\n",
       "      <td>6000.0000</td>\n",
       "      <td>5.905813e+05</td>\n",
       "      <td>1.184400e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1230</td>\n",
       "      <td>601012.SH</td>\n",
       "      <td>20120416</td>\n",
       "      <td>19.45</td>\n",
       "      <td>6.8081</td>\n",
       "      <td>6.8081</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20.4817</td>\n",
       "      <td>20.4817</td>\n",
       "      <td>1.9517</td>\n",
       "      <td>2.8836</td>\n",
       "      <td>2.8836</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>29918.0000</td>\n",
       "      <td>6000.0000</td>\n",
       "      <td>6000.0000</td>\n",
       "      <td>5.819051e+05</td>\n",
       "      <td>1.167000e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1229</td>\n",
       "      <td>601012.SH</td>\n",
       "      <td>20120417</td>\n",
       "      <td>18.88</td>\n",
       "      <td>7.4768</td>\n",
       "      <td>7.4768</td>\n",
       "      <td>NaN</td>\n",
       "      <td>19.8814</td>\n",
       "      <td>19.8814</td>\n",
       "      <td>1.8945</td>\n",
       "      <td>2.7991</td>\n",
       "      <td>2.7991</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>29918.0000</td>\n",
       "      <td>6000.0000</td>\n",
       "      <td>6000.0000</td>\n",
       "      <td>5.648518e+05</td>\n",
       "      <td>1.132800e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2283</th>\n",
       "      <td>397</td>\n",
       "      <td>601012.SH</td>\n",
       "      <td>20211101</td>\n",
       "      <td>100.20</td>\n",
       "      <td>3.5916</td>\n",
       "      <td>4.9248</td>\n",
       "      <td>1.72</td>\n",
       "      <td>63.4184</td>\n",
       "      <td>55.6194</td>\n",
       "      <td>11.7867</td>\n",
       "      <td>9.9367</td>\n",
       "      <td>7.0478</td>\n",
       "      <td>0.2643</td>\n",
       "      <td>0.1782</td>\n",
       "      <td>541295.2708</td>\n",
       "      <td>541283.2854</td>\n",
       "      <td>394748.2201</td>\n",
       "      <td>5.423779e+07</td>\n",
       "      <td>5.423659e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2284</th>\n",
       "      <td>1186</td>\n",
       "      <td>601012.SH</td>\n",
       "      <td>20211102</td>\n",
       "      <td>99.98</td>\n",
       "      <td>2.2636</td>\n",
       "      <td>3.1038</td>\n",
       "      <td>0.93</td>\n",
       "      <td>63.2792</td>\n",
       "      <td>55.4973</td>\n",
       "      <td>11.7609</td>\n",
       "      <td>9.9149</td>\n",
       "      <td>7.0323</td>\n",
       "      <td>0.2648</td>\n",
       "      <td>0.1786</td>\n",
       "      <td>541295.2708</td>\n",
       "      <td>541283.2854</td>\n",
       "      <td>394748.2201</td>\n",
       "      <td>5.411870e+07</td>\n",
       "      <td>5.411750e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2285</th>\n",
       "      <td>3546</td>\n",
       "      <td>601012.SH</td>\n",
       "      <td>20211103</td>\n",
       "      <td>91.00</td>\n",
       "      <td>3.6823</td>\n",
       "      <td>5.0493</td>\n",
       "      <td>1.38</td>\n",
       "      <td>57.5956</td>\n",
       "      <td>50.5126</td>\n",
       "      <td>10.7045</td>\n",
       "      <td>9.0244</td>\n",
       "      <td>6.4007</td>\n",
       "      <td>0.2910</td>\n",
       "      <td>0.1962</td>\n",
       "      <td>541295.2708</td>\n",
       "      <td>541283.2854</td>\n",
       "      <td>394748.2201</td>\n",
       "      <td>4.925787e+07</td>\n",
       "      <td>4.925678e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2286</th>\n",
       "      <td>2199</td>\n",
       "      <td>601012.SH</td>\n",
       "      <td>20211104</td>\n",
       "      <td>92.50</td>\n",
       "      <td>2.3978</td>\n",
       "      <td>3.2879</td>\n",
       "      <td>0.78</td>\n",
       "      <td>58.5450</td>\n",
       "      <td>51.3453</td>\n",
       "      <td>10.8810</td>\n",
       "      <td>9.1731</td>\n",
       "      <td>6.5062</td>\n",
       "      <td>0.2863</td>\n",
       "      <td>0.1931</td>\n",
       "      <td>541295.2708</td>\n",
       "      <td>541283.2854</td>\n",
       "      <td>394748.2201</td>\n",
       "      <td>5.006981e+07</td>\n",
       "      <td>5.006870e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2287</th>\n",
       "      <td>2444</td>\n",
       "      <td>601012.SH</td>\n",
       "      <td>20211105</td>\n",
       "      <td>90.00</td>\n",
       "      <td>2.2213</td>\n",
       "      <td>3.0458</td>\n",
       "      <td>NaN</td>\n",
       "      <td>56.9627</td>\n",
       "      <td>49.9576</td>\n",
       "      <td>10.5869</td>\n",
       "      <td>8.9252</td>\n",
       "      <td>6.3304</td>\n",
       "      <td>0.2942</td>\n",
       "      <td>0.1984</td>\n",
       "      <td>541295.2708</td>\n",
       "      <td>541283.2854</td>\n",
       "      <td>394748.2201</td>\n",
       "      <td>4.871657e+07</td>\n",
       "      <td>4.871550e+07</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2288 rows × 19 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      index    ts_code trade_date   close  turnover_rate  turnover_rate_f  \\\n",
       "0      1236  601012.SH   20120411   19.75        23.6622          23.6622   \n",
       "1      1223  601012.SH   20120412   19.47        13.9525          13.9525   \n",
       "2      1229  601012.SH   20120413   19.74        11.3160          11.3160   \n",
       "3      1230  601012.SH   20120416   19.45         6.8081           6.8081   \n",
       "4      1229  601012.SH   20120417   18.88         7.4768           7.4768   \n",
       "...     ...        ...        ...     ...            ...              ...   \n",
       "2283    397  601012.SH   20211101  100.20         3.5916           4.9248   \n",
       "2284   1186  601012.SH   20211102   99.98         2.2636           3.1038   \n",
       "2285   3546  601012.SH   20211103   91.00         3.6823           5.0493   \n",
       "2286   2199  601012.SH   20211104   92.50         2.3978           3.2879   \n",
       "2287   2444  601012.SH   20211105   90.00         2.2213           3.0458   \n",
       "\n",
       "      volume_ratio       pe   pe_ttm       pb      ps  ps_ttm  dv_ratio  \\\n",
       "0              NaN  20.7976  20.7976   1.9818  2.9281  2.9281       NaN   \n",
       "1              NaN  20.5027  20.5027   1.9537  2.8866  2.8866       NaN   \n",
       "2              NaN  20.7870  20.7870   1.9808  2.9266  2.9266       NaN   \n",
       "3              NaN  20.4817  20.4817   1.9517  2.8836  2.8836       NaN   \n",
       "4              NaN  19.8814  19.8814   1.8945  2.7991  2.7991       NaN   \n",
       "...            ...      ...      ...      ...     ...     ...       ...   \n",
       "2283          1.72  63.4184  55.6194  11.7867  9.9367  7.0478    0.2643   \n",
       "2284          0.93  63.2792  55.4973  11.7609  9.9149  7.0323    0.2648   \n",
       "2285          1.38  57.5956  50.5126  10.7045  9.0244  6.4007    0.2910   \n",
       "2286          0.78  58.5450  51.3453  10.8810  9.1731  6.5062    0.2863   \n",
       "2287           NaN  56.9627  49.9576  10.5869  8.9252  6.3304    0.2942   \n",
       "\n",
       "      dv_ttm  total_share  float_share   free_share      total_mv  \\\n",
       "0        NaN   29918.0000    6000.0000    6000.0000  5.908805e+05   \n",
       "1        NaN   29918.0000    6000.0000    6000.0000  5.825035e+05   \n",
       "2        NaN   29918.0000    6000.0000    6000.0000  5.905813e+05   \n",
       "3        NaN   29918.0000    6000.0000    6000.0000  5.819051e+05   \n",
       "4        NaN   29918.0000    6000.0000    6000.0000  5.648518e+05   \n",
       "...      ...          ...          ...          ...           ...   \n",
       "2283  0.1782  541295.2708  541283.2854  394748.2201  5.423779e+07   \n",
       "2284  0.1786  541295.2708  541283.2854  394748.2201  5.411870e+07   \n",
       "2285  0.1962  541295.2708  541283.2854  394748.2201  4.925787e+07   \n",
       "2286  0.1931  541295.2708  541283.2854  394748.2201  5.006981e+07   \n",
       "2287  0.1984  541295.2708  541283.2854  394748.2201  4.871657e+07   \n",
       "\n",
       "           circ_mv  \n",
       "0     1.185000e+05  \n",
       "1     1.168200e+05  \n",
       "2     1.184400e+05  \n",
       "3     1.167000e+05  \n",
       "4     1.132800e+05  \n",
       "...            ...  \n",
       "2283  5.423659e+07  \n",
       "2284  5.411750e+07  \n",
       "2285  4.925678e+07  \n",
       "2286  5.006870e+07  \n",
       "2287  4.871550e+07  \n",
       "\n",
       "[2288 rows x 19 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dd_dailybasic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "34c00dfa",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "427d98bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_stocks = pro.index_weight(index_code='000300.SH')\n",
    "df_stocks = df_stocks[df_stocks['trade_date']==df_stocks.loc[0,'trade_date']]\n",
    "df_stocks = df_stocks.sort_values(by=['con_code']).reset_index(drop=True)\n",
    "codes = list(df_stocks['con_code'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fc44712a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f80b0c75",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e5a05766",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "edee7ae3",
   "metadata": {},
   "outputs": [],
   "source": [
    "database_name='daily_kline.db'\n",
    "engine = create_engine(file_path+database_name)\n",
    "table_name = 'daily_kline'\n",
    "dd_kline = pd.read_sql(f\"select * from {table_name} where ts_code in {tuple(codes)}\",engine)\n",
    "dd_kline['trade_date'] = pd.to_datetime(dd_kline['trade_date'])\n",
    "dd_kline = dd_kline.sort_index()\n",
    "dd_kline = dd_kline.pivot(index='trade_date',columns='ts_code',values=['close'])\n",
    "cols = list(map(lambda x:x[1],dd_kline.columns))\n",
    "dd_kline.columns = cols\n",
    "\n",
    "\n",
    "database_name='daily_adj.db'\n",
    "engine = create_engine(file_path+database_name)\n",
    "table_name = 'daily_adj'\n",
    "dd_adj = pd.read_sql(f\"select * from {table_name} where ts_code in {tuple(codes)}\",engine)\n",
    "dd_adj['trade_date'] = pd.to_datetime(dd_adj['trade_date'])\n",
    "dd_adj = dd_adj.sort_index()\n",
    "dd_adj = dd_adj.pivot(index='trade_date',columns='ts_code',values=['adj_factor'])\n",
    "cols = list(map(lambda x:x[1],dd_adj.columns))\n",
    "dd_adj.columns = cols\n",
    "\n",
    "dd_close = (dd_kline*dd_adj/dd_adj.loc[dd_adj.index[-1]])\n",
    "\n",
    "dd_close = dd_close.round(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "749c6842",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "b882bb5c",
   "metadata": {},
   "outputs": [],
   "source": [
    "database_name='dailybasic.db'\n",
    "engine = create_engine(file_path+database_name)\n",
    "table_name = 'dailybasic'\n",
    "dd_dailybasic = pd.read_sql(f\"select * from {table_name} where ts_code in {tuple(codes)}\",engine)\n",
    "dd_dailybasic['trade_date'] = pd.to_datetime(dd_dailybasic['trade_date'])\n",
    "dd_dailybasic = dd_dailybasic.sort_index()\n",
    "\n",
    "\n",
    "dd_total_mv = dd_dailybasic.pivot(index='trade_date',columns='ts_code',values=['total_mv'])\n",
    "cols = list(map(lambda x:x[1],dd_total_mv.columns))\n",
    "dd_total_mv.columns = cols"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "a9dd3fa0",
   "metadata": {},
   "outputs": [],
   "source": [
    "dd_total_mv = dd_dailybasic.pivot(index='trade_date',columns='ts_code',values=['total_mv'])\n",
    "cols = list(map(lambda x:x[1],dd_total_mv.columns))\n",
    "dd_total_mv.columns = cols\n",
    "SIZE = np.log(dd_total_mv)\n",
    "\n",
    "dd_pb = dd_dailybasic.pivot(index='trade_date',columns='ts_code',values=['pb'])\n",
    "cols = list(map(lambda x:x[1],dd_pb.columns))\n",
    "dd_pb.columns = cols\n",
    "BP = 1/dd_bp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2de1d43c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6407f5e1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "889b4f4b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "trade_date\n",
       "2012-04-11     72.755107\n",
       "2012-04-12     75.090143\n",
       "2012-04-13     72.837651\n",
       "2012-04-16     75.258841\n",
       "2012-04-17     80.177517\n",
       "                 ...    \n",
       "2021-11-01    242.899662\n",
       "2021-11-02    242.331328\n",
       "2021-11-03    218.480864\n",
       "2021-11-04    222.556530\n",
       "2021-11-05    215.742347\n",
       "Length: 2288, dtype: float64"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "code = '601012.SH'\n",
    "\n",
    "y = (np.log(dd_total_mv)**3)[code]\n",
    "X = np.log(dd_total_mv)[code]\n",
    "X = sm.add_constant(X)\n",
    "model = sm.OLS(Y,X,missing='drop')\n",
    "res = model.fit()\n",
    "res.resid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "3154a4ca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "const       -6932.445578\n",
       "601012.SH     692.786122\n",
       "dtype: float64"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res.params"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "502ba1c8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "606ccfd4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "3f1cda34",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "trade_date\n",
       "2021-08-19    13.115728\n",
       "2021-08-20    11.757853\n",
       "2021-08-23    13.326700\n",
       "2021-08-24    16.676755\n",
       "2021-08-25    20.642426\n",
       "2021-08-26    18.326080\n",
       "2021-08-27    23.120720\n",
       "2021-08-30    29.621071\n",
       "2021-08-31    21.357285\n",
       "2021-09-01    16.708557\n",
       "2021-09-02    19.743425\n",
       "2021-09-03    17.027266\n",
       "2021-09-06    17.357749\n",
       "2021-09-07    18.729716\n",
       "2021-09-08    15.755105\n",
       "2021-09-09    13.766563\n",
       "2021-09-10    14.688201\n",
       "2021-09-13    12.202651\n",
       "2021-09-14    12.625504\n",
       "2021-09-15    14.723158\n",
       "2021-09-16    11.584907\n",
       "2021-09-17    10.727198\n",
       "2021-09-22    10.812659\n",
       "2021-09-23    10.596591\n",
       "2021-09-24    12.127837\n",
       "2021-09-27    13.213363\n",
       "2021-09-28    11.747780\n",
       "2021-09-29    11.209439\n",
       "2021-09-30    12.534093\n",
       "2021-10-08     9.613134\n",
       "2021-10-11     8.505573\n",
       "2021-10-12     8.177509\n",
       "2021-10-13    13.060748\n",
       "2021-10-14    11.859211\n",
       "2021-10-15    14.695398\n",
       "2021-10-18    15.636127\n",
       "2021-10-19    14.530473\n",
       "2021-10-20    17.288730\n",
       "2021-10-21    13.804933\n",
       "2021-10-22    13.930159\n",
       "2021-10-25    17.186745\n",
       "2021-10-26    15.516633\n",
       "2021-10-27    17.418628\n",
       "2021-10-28    18.022695\n",
       "2021-10-29    26.435882\n",
       "2021-11-01    28.773064\n",
       "2021-11-02    28.365804\n",
       "2021-11-03    19.279663\n",
       "2021-11-04    20.647934\n",
       "2021-11-05    18.071018\n",
       "dtype: float64"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def get_non_linear_size(code):\n",
    "    y = (np.log(dd_total_mv)**3)[code]\n",
    "    X = np.log(dd_total_mv)[code]\n",
    "    X = sm.add_constant(X)\n",
    "    \n",
    "    # 因子说明中，没有说是滚动的，但我个人倾向于用滚动的更好，避免使用未来数据\n",
    "    model = RollingOLS(endog=y,\n",
    "                       exog=X,\n",
    "                       window=252*2,\n",
    "                       expanding=True,\n",
    "                       min_nobs=42)\n",
    "\n",
    "    res = model.fit()\n",
    "    non_linear_size = y - (res.params * X).sum(1)\n",
    "    return non_linear_size\n",
    "\n",
    "code = '601012.SH'\n",
    "get_non_linear_size(code)[-50:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "74f4c92e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:xlabel='trade_date'>"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAD3CAYAAAAQYlNPAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAArW0lEQVR4nO3deXxU9dX48c+Zyb4HCIQ9IMgugrGyCIKKiv7wUay2Vq24oFVrbfu09mm1m7XqY11arfWRClitexWtCy7VUkChGnYVEMoaIBBIIGQjycz5/XFvwoABEjKZmeSe9+s1r7nznTs5Z2Yy33O/3ztzr6gqxhhjvMsX7QSMMcZElxUCY4zxOCsExhjjcVYIjDHG46wQGGOMx1khMMYYj4uLdgLN1alTJ83Ly4t2GsYY06YsWbJkt6rmNHZfmysEeXl5FBQURDsNY4xpU0Rk85Hus6khY4zxOCsExhj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4hwWALftM1UdD3QVkZOOELaxx34lxhFya2oMY1rECoHxus9U9dWQ27XA9cCzOKfmTAb6ACvc++vPkjYA5zzS84C+OIcNbkxjj20sRmOaGsOYFrFCYLymCud47/Wn/Dz8aJvX4UzbXA7Unxt4CzDEXT7ZvV4L/F5VJ+Cc5/lIR4ps7LGNxWgst6bGMKZF7JfFxlNEpAPwEs5W+E+Bu9yOtv7+8cCfcI4C6cc5R+xanHl+AeJxThf4KTAbyAXKgG+palkj8To18tjg4TFU9aNGclvSlBjGtJQVAmOM8Tj71pAxYeLO5Yfap6r/FY1cjGkOGxEYY4zH2c5iY4zxOCsExhjjcVYIjDHG46wQGGOMx1khMMYYj/v/oTwm+12GW6MAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "res.params.plot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6652550e",
   "metadata": {},
   "outputs": [],
   "source": [
    "X = sm.add_constant(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6a372456",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "2795d2f3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "const        -6.564480\n",
       "000001.SZ    12.973725\n",
       "000002.SZ    -6.128997\n",
       "000063.SZ   -12.402307\n",
       "000066.SZ    -9.494257\n",
       "               ...    \n",
       "688111.SH    -0.863829\n",
       "688126.SH   -38.598141\n",
       "688169.SH    -7.395711\n",
       "688363.SH   -30.024428\n",
       "688396.SH    10.848874\n",
       "Length: 301, dtype: float64"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Y = (np.log(dd_total_mv)**3)['601012.SH']\n",
    "X = np.log(dd_total_mv)\n",
    "X = sm.add_constant(X)\n",
    "model = sm.OLS(Y,X,missing='drop')\n",
    "res = model.fit()\n",
    "res.params"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7b82569f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "2100136e",
   "metadata": {},
   "outputs": [],
   "source": [
    "dd_close_ret = np.log(dd_close).diff()\n",
    "\n",
    "df_index = pro.index_daily(ts_code='399300.SZ', start_date='20100101')\n",
    "df_index.index = pd.to_datetime(df_index['trade_date'])\n",
    "df_index = df_index.sort_index()\n",
    "index_ret = np.log(df_index['close']).diff()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "87fe50ac",
   "metadata": {},
   "outputs": [],
   "source": [
    "def halflife_weighting(x,halflife):\n",
    "    span = 2/(1-np.exp(np.log(0.5)/halflife)) - 1\n",
    "    return x.ewm(span=span).mean()\n",
    "\n",
    "\n",
    "halflife = 63\n",
    "index_ewm_ret = halflife_weighting(index_ret,halflife)\n",
    "index_ewm_ret = sm.add_constant(index_ewm_ret)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "b1ece0f8",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "code = '601012.SH'\n",
    "\n",
    "stock = dd_close_ret[code]\n",
    "model = RollingOLS(endog=stock,\n",
    "                   exog=index_ewm_ret,\n",
    "                   window=252,\n",
    "                   expanding=True,\n",
    "                   min_nobs=42)\n",
    "\n",
    "res = model.fit()\n",
    "BETA = res.params['close']\n",
    "HSIGMA = res.mse_resid # 由于残差的均值为0，因此残差的标准差等价于The sum of squared residuals divided by the residual degrees of freedom"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 313,
   "id": "a54eb2e2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>close</th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>trade_date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2010-01-04</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-05</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-06</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-07</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-08</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-10-29</th>\n",
       "      <td>3.200804</td>\n",
       "      <td>0.001231</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-01</th>\n",
       "      <td>3.340603</td>\n",
       "      <td>0.001214</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-02</th>\n",
       "      <td>3.268077</td>\n",
       "      <td>0.001213</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-03</th>\n",
       "      <td>4.069877</td>\n",
       "      <td>0.001246</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-04</th>\n",
       "      <td>4.075402</td>\n",
       "      <td>0.001245</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2876 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "               close         0\n",
       "trade_date                    \n",
       "2010-01-04       NaN       NaN\n",
       "2010-01-05       NaN       NaN\n",
       "2010-01-06       NaN       NaN\n",
       "2010-01-07       NaN       NaN\n",
       "2010-01-08       NaN       NaN\n",
       "...              ...       ...\n",
       "2021-10-29  3.200804  0.001231\n",
       "2021-11-01  3.340603  0.001214\n",
       "2021-11-02  3.268077  0.001213\n",
       "2021-11-03  4.069877  0.001246\n",
       "2021-11-04  4.075402  0.001245\n",
       "\n",
       "[2876 rows x 2 columns]"
      ]
     },
     "execution_count": 313,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 301,
   "id": "b02a1131",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "trade_date\n",
       "2010-01-04         NaN\n",
       "2010-01-05         NaN\n",
       "2010-01-06         NaN\n",
       "2010-01-07         NaN\n",
       "2010-01-08         NaN\n",
       "                ...   \n",
       "2021-10-29    0.001231\n",
       "2021-11-01    0.001214\n",
       "2021-11-02    0.001213\n",
       "2021-11-03    0.001246\n",
       "2021-11-04    0.001245\n",
       "Length: 2876, dtype: float64"
      ]
     },
     "execution_count": 301,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res.ssr/res.df_resid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 315,
   "id": "632ec7f2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "trade_date\n",
       "2010-01-04         NaN\n",
       "2010-01-05         NaN\n",
       "2010-01-06         NaN\n",
       "2010-01-07         NaN\n",
       "2010-01-08         NaN\n",
       "                ...   \n",
       "2021-10-29    0.001231\n",
       "2021-11-01    0.001214\n",
       "2021-11-02    0.001213\n",
       "2021-11-03    0.001246\n",
       "2021-11-04    0.001245\n",
       "Length: 2876, dtype: float64"
      ]
     },
     "execution_count": 315,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res.mse_resid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 303,
   "id": "4ab832c7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "trade_date\n",
       "2010-01-04      0\n",
       "2010-01-05      0\n",
       "2010-01-06      0\n",
       "2010-01-07      0\n",
       "2010-01-08      0\n",
       "             ... \n",
       "2021-10-29    252\n",
       "2021-11-01    252\n",
       "2021-11-02    252\n",
       "2021-11-03    252\n",
       "2021-11-04    252\n",
       "Length: 2876, dtype: int32"
      ]
     },
     "execution_count": 303,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res.nobs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b5da2979",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "df68c3a6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 289,
   "id": "03137874",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "const    0.000239\n",
       "close    4.075402\n",
       "dtype: float64"
      ]
     },
     "execution_count": 289,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y = stock[-252:]\n",
    "X = index_ewm_ret[-252:]\n",
    "X = sm.add_constant(X)\n",
    "model = sm.OLS(y,X)\n",
    "res = model.fit()\n",
    "res.params"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 290,
   "id": "ca03777b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.3112013606652505"
      ]
     },
     "execution_count": 290,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(res.resid**2).sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 291,
   "id": "ce389b35",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.3112013606652505"
      ]
     },
     "execution_count": 291,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "((res.resid - res.resid.mean())**2).sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 294,
   "id": "1b567546",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "trade_date\n",
       "2020-10-23   -0.040793\n",
       "2020-10-26    0.033085\n",
       "2020-10-27    0.010720\n",
       "2020-10-28    0.007475\n",
       "2020-10-29    0.023447\n",
       "                ...   \n",
       "2021-10-29    0.092150\n",
       "2021-11-01    0.025862\n",
       "2021-11-02   -0.001247\n",
       "2021-11-03   -0.093000\n",
       "2021-11-04    0.017007\n",
       "Length: 252, dtype: float64"
      ]
     },
     "execution_count": 294,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res.resid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f6d5bfa6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 273,
   "id": "658704e7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0012448054426610026"
      ]
     },
     "execution_count": 273,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res.mse_resid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 277,
   "id": "d9ca7170",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.5578542467932377"
      ]
     },
     "execution_count": 277,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(res.resid**2).sum()**0.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 280,
   "id": "6e6b6f57",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.001244805442661002"
      ]
     },
     "execution_count": 280,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(res.resid**2).sum()/250"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6e139aef",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a4a75ffd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0f467c1a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 233,
   "id": "59d61bf7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.035211447832023214"
      ]
     },
     "execution_count": 233,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res.resid.std()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9f278305",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "372279cb",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7a82fd9f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 187,
   "id": "18089a4a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>const</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>trade_date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2010-01-04</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-05</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-06</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-07</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-08</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-10-29</th>\n",
       "      <td>2.0</td>\n",
       "      <td>0.002190</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-01</th>\n",
       "      <td>2.0</td>\n",
       "      <td>0.002252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-02</th>\n",
       "      <td>2.0</td>\n",
       "      <td>0.002192</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-03</th>\n",
       "      <td>2.0</td>\n",
       "      <td>0.001997</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-04</th>\n",
       "      <td>2.0</td>\n",
       "      <td>0.001774</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2876 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            const     close\n",
       "trade_date                 \n",
       "2010-01-04    NaN       NaN\n",
       "2010-01-05    NaN       NaN\n",
       "2010-01-06    NaN       NaN\n",
       "2010-01-07    NaN       NaN\n",
       "2010-01-08    NaN       NaN\n",
       "...           ...       ...\n",
       "2021-10-29    2.0  0.002190\n",
       "2021-11-01    2.0  0.002252\n",
       "2021-11-02    2.0  0.002192\n",
       "2021-11-03    2.0  0.001997\n",
       "2021-11-04    2.0  0.001774\n",
       "\n",
       "[2876 rows x 2 columns]"
      ]
     },
     "execution_count": 187,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index_ewm_ret.rolling(252).apply(lambda x:x[0]+x[1])"
   ]
  },
  {
   "cell_type": "raw",
   "id": "14969d26",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "78658e84",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "id": "389afbf0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<AxesSubplot:xlabel='trade_date'>"
      ]
     },
     "execution_count": 149,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXEAAAD3CAYAAADrGWTVAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAA6PklEQVR4nO2dd5hTZdbAf28yfWDovTggSm+KgIoIgojdtTdcXAVd2+p+64odsa7u6q6ujV3bWlB0LaxIUQQRAanSi3SG3mdgmJa83x/33kySycwkk3on5/c8PCQ39+acSW7OPfe8pyitNYIgCII9ccRbAUEQBKHmiBEXBEGwMWLEBUEQbIwYcUEQBBsjRlwQBMHGiBEXBEGwMSmh7KyUqgd8DDiBY8A1wAZgk7nL3VrrFVW9R+PGjXVubm7omgqCICQxixcv3q+1buK/XYWSJ66UugP4VWv9rVLqdWAXkK21fiDY9+jTp49etGhR0DIFQRAEUEot1lr38d8eUjhFa/2a1vpb82kToAy4SCm1QCn1llIqJM9eEARBCI8axcSVUqcDDYBvgaFa675AKnBBBHUTBEEQqiFkz1kp1RB4BbgC2K21LjZfWgScVMkxo4HRAG3btq2ZpoIgCEIFQl3YTAM+BR7UWm9VSk1USj0NrAQuA54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O8ZafCDoku/xE0CHe8oPV4Sxz33e11idrIzNJ5EeRKlPutJHN8QN4+k+001oPVUpdCzwJHMJIG4rEVTYhdYi3/ETQIdnlJ4IO8ZYfgg67gCKt9TaRHxuCyps2V7RLMVJkOgMdgWkYSm/XWu+JnoqJoUO85SeCDskuPxF0iLf8IHXYK/JjSFWrnt7/MJLY3cBU4KZgj4vkv3jrEG/5iaBDsstPBB3iLT8RdEh2+d7/gm6ApYwS2n4YaUMlwV0iIku8dYi3/ETQIdnlJ4IO8ZafCDoku3wfXUIw4jHpvpbIOsRbfiLokOzyE0GHeMtPBB2SXb43MmNTEATBxsR90ocgCIJQc8SIC4Ig2Bgx4oIgCDZGjLhgK5RSvZRSvcI4fqyq4WCG6o4NVzdBqAlixAW70cv8l4j0InF1E2op0Zp0IwgRRyn1LEaPdpRSI7TWQ5RSszBmqvbQWp+nlKqD0eM5G9igtb5ZKdUA+BRjKIECZiljssx/MMa3rdBa31mJzEDHBpIRSLegZAhCOIgnLtgGrfWDGGPOntNaDzE39wfmaa2tuY0tgFcw+sjnKqWaYQyq/VprPRijXBpz20qt9UCghVKqRyViAx1bQUYlugUrQxBqjBhxwe6s1Fp/7vW8FLgV+BBjHF0m0A5YZr5uTRfqiDH7dBbGQO3KZn8GOjaQjEAEK0MQaowYccFuHMfo2WyNuvPv2ncLRqjjOsCaZbkN6Go+7mX+vw74u9Z6EMZc0sq6zgU6NpCMQLoFK0MQaoxUbAq2QinVEJiI4f0+CIwzjaT1+kDgNYyOck6MuYbrMOLaCkjFGJO1EHgHaA7kA9drrfMDyGsc4Fi3vwyt9U8BdFscjAxBCAcx4oIgCDZGslMEwcSMXXtzRGt9aTx0EYRgEU9cEATBxsjCpiAIgo0RIy4IgmBjxIgLgiDYGDHigiAINkaMuCAIgo35f+QfYmvDSSlPAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "code = '601012.SH'\n",
    "stock = dd_close_ret[code]\n",
    "model = RollingOLS(endog=stock,\n",
    "                   exog=index_ewm_ret,\n",
    "                   window=252,\n",
    "                   expanding=True,\n",
    "                   min_nobs=42)\n",
    "res = model.fit()\n",
    "res.params.plot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c38ea42d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 167,
   "id": "513f25f0",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import statsmodels.api as sm\n",
    "import numpy as np\n",
    "from statsmodels.regression.rolling import RollingOLS\n",
    "\n",
    "index = pd.date_range(\"2000-1-1\",periods=250, freq=\"M\")\n",
    "y = pd.Series(np.random.standard_normal(250),index=index)\n",
    "x = sm.add_constant(pd.DataFrame(np.random.standard_normal((250,3)),index=index))\n",
    "#x = sm.add_constant(pd.DataFrame(np.random.standard_normal((250,3)),index=index))\n",
    "\n",
    "res = RollingOLS(y,x, window=60).fit()\n",
    "rolling_resid = y - (res.params * x).sum(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 176,
   "id": "81a850ec",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>const</th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2000-01-31</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-02-29</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-03-31</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-04-30</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-05-31</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-06-30</th>\n",
       "      <td>0.018447</td>\n",
       "      <td>-0.457132</td>\n",
       "      <td>-0.021567</td>\n",
       "      <td>0.085217</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-07-31</th>\n",
       "      <td>0.041943</td>\n",
       "      <td>-0.469897</td>\n",
       "      <td>-0.037414</td>\n",
       "      <td>0.098289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-08-31</th>\n",
       "      <td>0.055105</td>\n",
       "      <td>-0.465634</td>\n",
       "      <td>-0.048137</td>\n",
       "      <td>0.123155</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-09-30</th>\n",
       "      <td>-0.008362</td>\n",
       "      <td>-0.410776</td>\n",
       "      <td>-0.041290</td>\n",
       "      <td>0.119125</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-10-31</th>\n",
       "      <td>-0.034591</td>\n",
       "      <td>-0.436101</td>\n",
       "      <td>-0.071383</td>\n",
       "      <td>0.139187</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>250 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "               const         0         1         2\n",
       "2000-01-31       NaN       NaN       NaN       NaN\n",
       "2000-02-29       NaN       NaN       NaN       NaN\n",
       "2000-03-31       NaN       NaN       NaN       NaN\n",
       "2000-04-30       NaN       NaN       NaN       NaN\n",
       "2000-05-31       NaN       NaN       NaN       NaN\n",
       "...              ...       ...       ...       ...\n",
       "2020-06-30  0.018447 -0.457132 -0.021567  0.085217\n",
       "2020-07-31  0.041943 -0.469897 -0.037414  0.098289\n",
       "2020-08-31  0.055105 -0.465634 -0.048137  0.123155\n",
       "2020-09-30 -0.008362 -0.410776 -0.041290  0.119125\n",
       "2020-10-31 -0.034591 -0.436101 -0.071383  0.139187\n",
       "\n",
       "[250 rows x 4 columns]"
      ]
     },
     "execution_count": 176,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res.params"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f7602756",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "be0e94a2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "id": "c9bf8b01",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "close    2.843258\n",
       "dtype: float64"
      ]
     },
     "execution_count": 143,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#>>> X = sm.add_constant(X)\n",
    ">>> model = sm.OLS(stock,index_ewm_ret,missing='drop')\n",
    ">>> results = model.fit()\n",
    ">>> results.params"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "id": "5e70d469",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "trade_date\n",
       "2012-04-12   -0.013115\n",
       "2012-04-13    0.014726\n",
       "2012-04-16   -0.013177\n",
       "2012-04-17   -0.027381\n",
       "2012-04-18    0.014864\n",
       "                ...   \n",
       "2021-10-29    0.092215\n",
       "2021-11-01    0.025879\n",
       "2021-11-02   -0.001368\n",
       "2021-11-03   -0.093169\n",
       "2021-11-04    0.016974\n",
       "Length: 2278, dtype: float64"
      ]
     },
     "execution_count": 150,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results.resid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "id": "6d260069",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "trade_date\n",
       "2010-01-04         NaN\n",
       "2010-01-05         NaN\n",
       "2010-01-06         NaN\n",
       "2010-01-07         NaN\n",
       "2010-01-08         NaN\n",
       "                ...   \n",
       "2021-10-29    0.092215\n",
       "2021-11-01    0.025879\n",
       "2021-11-02   -0.001368\n",
       "2021-11-03   -0.093169\n",
       "2021-11-04    0.016974\n",
       "Length: 2876, dtype: float64"
      ]
     },
     "execution_count": 157,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock - index_ewm_ret * results.params['close']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 154,
   "id": "d916bf33",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "close    2.843258\n",
       "dtype: float64"
      ]
     },
     "execution_count": 154,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results.params"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "id": "dcbdee94",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "trade_date\n",
       "2010-01-04         NaN\n",
       "2010-01-05    0.008116\n",
       "2010-01-06    0.000879\n",
       "2010-01-07   -0.006171\n",
       "2010-01-08   -0.003969\n",
       "                ...   \n",
       "2021-10-29   -0.000141\n",
       "2021-11-01   -0.000179\n",
       "2021-11-02   -0.000292\n",
       "2021-11-03   -0.000331\n",
       "2021-11-04   -0.000220\n",
       "Name: close, Length: 2876, dtype: float64"
      ]
     },
     "execution_count": 155,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index_ewm_ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aae93fdd",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "id": "01f990c7",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'model': <statsmodels.regression.rolling.RollingOLS at 0x2348adee8e0>,\n",
       " '_params': array([[       nan],\n",
       "        [       nan],\n",
       "        [       nan],\n",
       "        ...,\n",
       "        [4.09633999],\n",
       "        [4.31851974],\n",
       "        [4.44765925]]),\n",
       " '_ssr': array([       nan,        nan,        nan, ..., 0.30438643, 0.31185515,\n",
       "        0.3114726 ]),\n",
       " '_llf': array([         nan,          nan,          nan, ..., 489.00716784,\n",
       "        485.95282835, 486.10748545]),\n",
       " '_nobs': array([  0,   0,   0, ..., 252, 252, 252]),\n",
       " '_s2': array([       nan,        nan,        nan, ..., 0.00121269, 0.00124245,\n",
       "        0.00124093]),\n",
       " '_xpxi': array([[[          nan]],\n",
       " \n",
       "        [[          nan]],\n",
       " \n",
       "        [[          nan]],\n",
       " \n",
       "        ...,\n",
       " \n",
       "        [[4615.65219642]],\n",
       " \n",
       "        [[4645.78609548]],\n",
       " \n",
       "        [[4674.88796438]]]),\n",
       " '_xepxe': array([[[           nan]],\n",
       " \n",
       "        [[           nan]],\n",
       " \n",
       "        [[           nan]],\n",
       " \n",
       "        ...,\n",
       " \n",
       "        [[2.96011268e-07]],\n",
       " \n",
       "        [[2.95923317e-07]],\n",
       " \n",
       "        [[2.94981339e-07]]]),\n",
       " '_centered_tss': array([       nan,        nan,        nan, ..., 0.30543107, 0.31373726,\n",
       "        0.31334881]),\n",
       " '_uncentered_tss': array([       nan,        nan,        nan, ..., 0.30802188, 0.31586946,\n",
       "        0.31570408]),\n",
       " '_k_constant': 0,\n",
       " '_nvar': 1,\n",
       " '_use_t': False,\n",
       " '_cov_type': 'nonrobust',\n",
       " '_use_pandas': True,\n",
       " '_data_attr': [],\n",
       " '_cache': {'params':                close\n",
       "  trade_date          \n",
       "  2010-01-04       NaN\n",
       "  2010-01-05       NaN\n",
       "  2010-01-06       NaN\n",
       "  2010-01-07       NaN\n",
       "  2010-01-08       NaN\n",
       "  ...              ...\n",
       "  2021-10-29  3.847351\n",
       "  2021-11-01  4.192011\n",
       "  2021-11-02  4.096340\n",
       "  2021-11-03  4.318520\n",
       "  2021-11-04  4.447659\n",
       "  \n",
       "  [2876 rows x 1 columns]}}"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vars(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "id": "6ec231da",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'RollingRegressionResults' object has no attribute 'resid'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-111-1c6ac88947d9>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mres\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mresid\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m: 'RollingRegressionResults' object has no attribute 'resid'"
     ]
    }
   ],
   "source": [
    "res.resid"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ad1a72d9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "id": "ef114140",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>000001.SZ</th>\n",
       "      <th>000002.SZ</th>\n",
       "      <th>000063.SZ</th>\n",
       "      <th>000066.SZ</th>\n",
       "      <th>000069.SZ</th>\n",
       "      <th>000100.SZ</th>\n",
       "      <th>000157.SZ</th>\n",
       "      <th>000166.SZ</th>\n",
       "      <th>000333.SZ</th>\n",
       "      <th>000338.SZ</th>\n",
       "      <th>...</th>\n",
       "      <th>603993.SH</th>\n",
       "      <th>688008.SH</th>\n",
       "      <th>688009.SH</th>\n",
       "      <th>688012.SH</th>\n",
       "      <th>688036.SH</th>\n",
       "      <th>688111.SH</th>\n",
       "      <th>688126.SH</th>\n",
       "      <th>688169.SH</th>\n",
       "      <th>688363.SH</th>\n",
       "      <th>688396.SH</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>trade_date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2010-01-04</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-05</th>\n",
       "      <td>-0.017083</td>\n",
       "      <td>-0.023546</td>\n",
       "      <td>0.019004</td>\n",
       "      <td>0.055341</td>\n",
       "      <td>-0.042125</td>\n",
       "      <td>0.028571</td>\n",
       "      <td>-0.018215</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.021484</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-06</th>\n",
       "      <td>-0.017380</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.020665</td>\n",
       "      <td>-0.007317</td>\n",
       "      <td>0.009560</td>\n",
       "      <td>-0.018519</td>\n",
       "      <td>0.040816</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.089820</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-07</th>\n",
       "      <td>-0.010884</td>\n",
       "      <td>-0.007092</td>\n",
       "      <td>-0.046320</td>\n",
       "      <td>-0.001229</td>\n",
       "      <td>-0.015152</td>\n",
       "      <td>-0.009434</td>\n",
       "      <td>-0.028520</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.001832</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-08</th>\n",
       "      <td>-0.002751</td>\n",
       "      <td>0.007143</td>\n",
       "      <td>0.004317</td>\n",
       "      <td>0.024600</td>\n",
       "      <td>0.011538</td>\n",
       "      <td>0.019048</td>\n",
       "      <td>-0.018349</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.016514</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-10-29</th>\n",
       "      <td>-0.011156</td>\n",
       "      <td>-0.048092</td>\n",
       "      <td>-0.010316</td>\n",
       "      <td>0.019712</td>\n",
       "      <td>-0.014173</td>\n",
       "      <td>0.013378</td>\n",
       "      <td>-0.016194</td>\n",
       "      <td>-0.007737</td>\n",
       "      <td>0.009542</td>\n",
       "      <td>0.002656</td>\n",
       "      <td>...</td>\n",
       "      <td>0.006723</td>\n",
       "      <td>0.116638</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.088729</td>\n",
       "      <td>-0.006977</td>\n",
       "      <td>0.125090</td>\n",
       "      <td>0.018412</td>\n",
       "      <td>0.022704</td>\n",
       "      <td>0.046262</td>\n",
       "      <td>0.028638</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-01</th>\n",
       "      <td>-0.005641</td>\n",
       "      <td>-0.001098</td>\n",
       "      <td>-0.037707</td>\n",
       "      <td>-0.004461</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.051155</td>\n",
       "      <td>-0.004115</td>\n",
       "      <td>0.042885</td>\n",
       "      <td>0.058747</td>\n",
       "      <td>-0.001987</td>\n",
       "      <td>...</td>\n",
       "      <td>0.001669</td>\n",
       "      <td>0.106144</td>\n",
       "      <td>0.002028</td>\n",
       "      <td>0.005122</td>\n",
       "      <td>-0.041142</td>\n",
       "      <td>0.015985</td>\n",
       "      <td>-0.012052</td>\n",
       "      <td>0.086656</td>\n",
       "      <td>0.015060</td>\n",
       "      <td>0.013273</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-02</th>\n",
       "      <td>-0.062403</td>\n",
       "      <td>-0.030236</td>\n",
       "      <td>-0.007327</td>\n",
       "      <td>-0.011202</td>\n",
       "      <td>-0.028754</td>\n",
       "      <td>-0.037677</td>\n",
       "      <td>-0.034435</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>-0.027469</td>\n",
       "      <td>-0.021234</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.026667</td>\n",
       "      <td>0.001111</td>\n",
       "      <td>-0.010121</td>\n",
       "      <td>-0.001274</td>\n",
       "      <td>0.002310</td>\n",
       "      <td>-0.030000</td>\n",
       "      <td>0.036240</td>\n",
       "      <td>0.026595</td>\n",
       "      <td>-0.006528</td>\n",
       "      <td>0.034824</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-03</th>\n",
       "      <td>-0.008251</td>\n",
       "      <td>0.023243</td>\n",
       "      <td>-0.002567</td>\n",
       "      <td>0.015106</td>\n",
       "      <td>-0.014803</td>\n",
       "      <td>0.017945</td>\n",
       "      <td>-0.001427</td>\n",
       "      <td>-0.005607</td>\n",
       "      <td>-0.021042</td>\n",
       "      <td>0.006102</td>\n",
       "      <td>...</td>\n",
       "      <td>0.010274</td>\n",
       "      <td>0.004023</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.002232</td>\n",
       "      <td>-0.018704</td>\n",
       "      <td>-0.022749</td>\n",
       "      <td>-0.000346</td>\n",
       "      <td>-0.027888</td>\n",
       "      <td>0.008483</td>\n",
       "      <td>0.002161</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-04</th>\n",
       "      <td>-0.008874</td>\n",
       "      <td>0.000554</td>\n",
       "      <td>0.018983</td>\n",
       "      <td>0.026042</td>\n",
       "      <td>-0.001669</td>\n",
       "      <td>0.001603</td>\n",
       "      <td>0.005714</td>\n",
       "      <td>0.001880</td>\n",
       "      <td>0.020196</td>\n",
       "      <td>0.023585</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.038983</td>\n",
       "      <td>0.004007</td>\n",
       "      <td>0.004090</td>\n",
       "      <td>-0.002864</td>\n",
       "      <td>0.023490</td>\n",
       "      <td>-0.007174</td>\n",
       "      <td>0.000693</td>\n",
       "      <td>-0.006148</td>\n",
       "      <td>0.007582</td>\n",
       "      <td>0.042206</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2876 rows × 300 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            000001.SZ  000002.SZ  000063.SZ  000066.SZ  000069.SZ  000100.SZ  \\\n",
       "trade_date                                                                     \n",
       "2010-01-04        NaN        NaN        NaN        NaN        NaN        NaN   \n",
       "2010-01-05  -0.017083  -0.023546   0.019004   0.055341  -0.042125   0.028571   \n",
       "2010-01-06  -0.017380   0.000000  -0.020665  -0.007317   0.009560  -0.018519   \n",
       "2010-01-07  -0.010884  -0.007092  -0.046320  -0.001229  -0.015152  -0.009434   \n",
       "2010-01-08  -0.002751   0.007143   0.004317   0.024600   0.011538   0.019048   \n",
       "...               ...        ...        ...        ...        ...        ...   \n",
       "2021-10-29  -0.011156  -0.048092  -0.010316   0.019712  -0.014173   0.013378   \n",
       "2021-11-01  -0.005641  -0.001098  -0.037707  -0.004461   0.000000   0.051155   \n",
       "2021-11-02  -0.062403  -0.030236  -0.007327  -0.011202  -0.028754  -0.037677   \n",
       "2021-11-03  -0.008251   0.023243  -0.002567   0.015106  -0.014803   0.017945   \n",
       "2021-11-04  -0.008874   0.000554   0.018983   0.026042  -0.001669   0.001603   \n",
       "\n",
       "            000157.SZ  000166.SZ  000333.SZ  000338.SZ  ...  603993.SH  \\\n",
       "trade_date                                              ...              \n",
       "2010-01-04        NaN        NaN        NaN        NaN  ...        NaN   \n",
       "2010-01-05  -0.018215        NaN        NaN  -0.021484  ...        NaN   \n",
       "2010-01-06   0.040816        NaN        NaN   0.089820  ...        NaN   \n",
       "2010-01-07  -0.028520        NaN        NaN  -0.001832  ...        NaN   \n",
       "2010-01-08  -0.018349        NaN        NaN   0.016514  ...        NaN   \n",
       "...               ...        ...        ...        ...  ...        ...   \n",
       "2021-10-29  -0.016194  -0.007737   0.009542   0.002656  ...   0.006723   \n",
       "2021-11-01  -0.004115   0.042885   0.058747  -0.001987  ...   0.001669   \n",
       "2021-11-02  -0.034435   0.000000  -0.027469  -0.021234  ...  -0.026667   \n",
       "2021-11-03  -0.001427  -0.005607  -0.021042   0.006102  ...   0.010274   \n",
       "2021-11-04   0.005714   0.001880   0.020196   0.023585  ...  -0.038983   \n",
       "\n",
       "            688008.SH  688009.SH  688012.SH  688036.SH  688111.SH  688126.SH  \\\n",
       "trade_date                                                                     \n",
       "2010-01-04        NaN        NaN        NaN        NaN        NaN        NaN   \n",
       "2010-01-05        NaN        NaN        NaN        NaN        NaN        NaN   \n",
       "2010-01-06        NaN        NaN        NaN        NaN        NaN        NaN   \n",
       "2010-01-07        NaN        NaN        NaN        NaN        NaN        NaN   \n",
       "2010-01-08        NaN        NaN        NaN        NaN        NaN        NaN   \n",
       "...               ...        ...        ...        ...        ...        ...   \n",
       "2021-10-29   0.116638   0.000000   0.088729  -0.006977   0.125090   0.018412   \n",
       "2021-11-01   0.106144   0.002028   0.005122  -0.041142   0.015985  -0.012052   \n",
       "2021-11-02   0.001111  -0.010121  -0.001274   0.002310  -0.030000   0.036240   \n",
       "2021-11-03   0.004023   0.000000   0.002232  -0.018704  -0.022749  -0.000346   \n",
       "2021-11-04   0.004007   0.004090  -0.002864   0.023490  -0.007174   0.000693   \n",
       "\n",
       "            688169.SH  688363.SH  688396.SH  \n",
       "trade_date                                   \n",
       "2010-01-04        NaN        NaN        NaN  \n",
       "2010-01-05        NaN        NaN        NaN  \n",
       "2010-01-06        NaN        NaN        NaN  \n",
       "2010-01-07        NaN        NaN        NaN  \n",
       "2010-01-08        NaN        NaN        NaN  \n",
       "...               ...        ...        ...  \n",
       "2021-10-29   0.022704   0.046262   0.028638  \n",
       "2021-11-01   0.086656   0.015060   0.013273  \n",
       "2021-11-02   0.026595  -0.006528   0.034824  \n",
       "2021-11-03  -0.027888   0.008483   0.002161  \n",
       "2021-11-04  -0.006148   0.007582   0.042206  \n",
       "\n",
       "[2876 rows x 300 columns]"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dd_close_ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "565190bc",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "34d98cd3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "52f5d8fd",
   "metadata": {},
   "outputs": [],
   "source": [
    "results = PandasRollingOLS(dd_close_ret['601012.SH'], df_index, 252)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "a2f5cb39",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "trade_date\n",
       "2010-01-04         NaN\n",
       "2010-01-05         NaN\n",
       "2010-01-06         NaN\n",
       "2010-01-07         NaN\n",
       "2010-01-08         NaN\n",
       "                ...   \n",
       "2021-10-29    0.096162\n",
       "2021-11-01    0.025694\n",
       "2021-11-02   -0.002196\n",
       "2021-11-03   -0.089818\n",
       "2021-11-04    0.016484\n",
       "Name: 601012.SH, Length: 2876, dtype: float64"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dd_close_ret['601012.SH']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "537d953c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>feature1</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>trade_date</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2013-04-24</th>\n",
       "      <td>0.772308</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-04-25</th>\n",
       "      <td>0.785978</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-04-26</th>\n",
       "      <td>0.792832</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-05-02</th>\n",
       "      <td>0.792221</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2013-05-03</th>\n",
       "      <td>0.790094</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-10-29</th>\n",
       "      <td>1.480793</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-01</th>\n",
       "      <td>1.465613</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-02</th>\n",
       "      <td>1.460949</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-03</th>\n",
       "      <td>1.470657</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-04</th>\n",
       "      <td>1.468675</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2076 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            feature1\n",
       "trade_date          \n",
       "2013-04-24  0.772308\n",
       "2013-04-25  0.785978\n",
       "2013-04-26  0.792832\n",
       "2013-05-02  0.792221\n",
       "2013-05-03  0.790094\n",
       "...              ...\n",
       "2021-10-29  1.480793\n",
       "2021-11-01  1.465613\n",
       "2021-11-02  1.460949\n",
       "2021-11-03  1.470657\n",
       "2021-11-04  1.468675\n",
       "\n",
       "[2076 rows x 1 columns]"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results.beta.dropna()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "81891fe8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>feature1</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>trade_date</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2012-02-15</th>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-02-16</th>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-02-17</th>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-02-20</th>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2012-02-21</th>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-10-29</th>\n",
       "      <td>1.480793</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-01</th>\n",
       "      <td>1.465613</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-02</th>\n",
       "      <td>1.460949</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-03</th>\n",
       "      <td>1.470657</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-04</th>\n",
       "      <td>1.468675</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2365 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            feature1\n",
       "trade_date          \n",
       "2012-02-15       NaN\n",
       "2012-02-16       NaN\n",
       "2012-02-17       NaN\n",
       "2012-02-20       NaN\n",
       "2012-02-21       NaN\n",
       "...              ...\n",
       "2021-10-29  1.480793\n",
       "2021-11-01  1.465613\n",
       "2021-11-02  1.460949\n",
       "2021-11-03  1.470657\n",
       "2021-11-04  1.468675\n",
       "\n",
       "[2365 rows x 1 columns]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results.beta[260:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c0eb0c8f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d689f4ed",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9541f21d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "ebc81741",
   "metadata": {},
   "outputs": [],
   "source": [
    "database_name='dailybasic.db'\n",
    "engine = create_engine(file_path+database_name)\n",
    "table_name = 'dailybasic'\n",
    "dd_dailybasic = pd.read_sql(f\"select * from {table_name} where ts_code in {tuple(codes)}\",engine)\n",
    "dd_dailybasic['trade_date'] = pd.to_datetime(dd_dailybasic['trade_date'])\n",
    "dd_dailybasic = dd_dailybasic.sort_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "26be1675",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "fd747d4e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"10\" halign=\"left\">pe_ttm</th>\n",
       "      <th>...</th>\n",
       "      <th colspan=\"10\" halign=\"left\">total_mv</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ts_code</th>\n",
       "      <th>000001.SZ</th>\n",
       "      <th>000002.SZ</th>\n",
       "      <th>000063.SZ</th>\n",
       "      <th>000066.SZ</th>\n",
       "      <th>000069.SZ</th>\n",
       "      <th>000100.SZ</th>\n",
       "      <th>000157.SZ</th>\n",
       "      <th>000166.SZ</th>\n",
       "      <th>000333.SZ</th>\n",
       "      <th>000338.SZ</th>\n",
       "      <th>...</th>\n",
       "      <th>603993.SH</th>\n",
       "      <th>688008.SH</th>\n",
       "      <th>688009.SH</th>\n",
       "      <th>688012.SH</th>\n",
       "      <th>688036.SH</th>\n",
       "      <th>688111.SH</th>\n",
       "      <th>688126.SH</th>\n",
       "      <th>688169.SH</th>\n",
       "      <th>688363.SH</th>\n",
       "      <th>688396.SH</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>trade_date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2010-01-04</th>\n",
       "      <td>78.7940</td>\n",
       "      <td>24.7229</td>\n",
       "      <td>40.8265</td>\n",
       "      <td>46.8105</td>\n",
       "      <td>52.3775</td>\n",
       "      <td>82.8030</td>\n",
       "      <td>23.0347</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>23.0861</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-05</th>\n",
       "      <td>77.4315</td>\n",
       "      <td>24.1631</td>\n",
       "      <td>41.5908</td>\n",
       "      <td>49.3774</td>\n",
       "      <td>50.1030</td>\n",
       "      <td>85.3557</td>\n",
       "      <td>22.6384</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>22.6253</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-06</th>\n",
       "      <td>76.1022</td>\n",
       "      <td>24.1631</td>\n",
       "      <td>40.7365</td>\n",
       "      <td>49.0313</td>\n",
       "      <td>50.6084</td>\n",
       "      <td>83.4412</td>\n",
       "      <td>23.5392</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>24.6574</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-07</th>\n",
       "      <td>75.2714</td>\n",
       "      <td>23.9766</td>\n",
       "      <td>38.8571</td>\n",
       "      <td>48.9737</td>\n",
       "      <td>49.8502</td>\n",
       "      <td>82.8030</td>\n",
       "      <td>22.8816</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>24.6030</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-08</th>\n",
       "      <td>75.1052</td>\n",
       "      <td>24.1398</td>\n",
       "      <td>39.0190</td>\n",
       "      <td>50.1562</td>\n",
       "      <td>50.3873</td>\n",
       "      <td>84.2389</td>\n",
       "      <td>22.4672</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>24.9949</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-10-28</th>\n",
       "      <td>10.7300</td>\n",
       "      <td>5.5522</td>\n",
       "      <td>20.6761</td>\n",
       "      <td>33.8484</td>\n",
       "      <td>4.7971</td>\n",
       "      <td>7.3182</td>\n",
       "      <td>7.9264</td>\n",
       "      <td>15.6873</td>\n",
       "      <td>16.8023</td>\n",
       "      <td>11.9926</td>\n",
       "      <td>...</td>\n",
       "      <td>1.285155e+07</td>\n",
       "      <td>6.593907e+06</td>\n",
       "      <td>5220780.767</td>\n",
       "      <td>8.841260e+06</td>\n",
       "      <td>1.275490e+07</td>\n",
       "      <td>12098945.0</td>\n",
       "      <td>6870320.20</td>\n",
       "      <td>5.877691e+06</td>\n",
       "      <td>7615680.0</td>\n",
       "      <td>7.928472e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-10-29</th>\n",
       "      <td>10.6103</td>\n",
       "      <td>5.5214</td>\n",
       "      <td>20.4628</td>\n",
       "      <td>34.5156</td>\n",
       "      <td>4.7291</td>\n",
       "      <td>7.4161</td>\n",
       "      <td>8.6129</td>\n",
       "      <td>15.5659</td>\n",
       "      <td>16.9626</td>\n",
       "      <td>12.0245</td>\n",
       "      <td>...</td>\n",
       "      <td>1.293795e+07</td>\n",
       "      <td>7.363008e+06</td>\n",
       "      <td>5220780.767</td>\n",
       "      <td>9.625739e+06</td>\n",
       "      <td>1.266592e+07</td>\n",
       "      <td>13612408.0</td>\n",
       "      <td>6996813.46</td>\n",
       "      <td>6.011138e+06</td>\n",
       "      <td>7968000.0</td>\n",
       "      <td>8.155528e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-01</th>\n",
       "      <td>10.5504</td>\n",
       "      <td>5.5153</td>\n",
       "      <td>19.6912</td>\n",
       "      <td>32.9725</td>\n",
       "      <td>4.7291</td>\n",
       "      <td>7.7955</td>\n",
       "      <td>8.5775</td>\n",
       "      <td>15.4933</td>\n",
       "      <td>17.7359</td>\n",
       "      <td>13.1487</td>\n",
       "      <td>...</td>\n",
       "      <td>1.295954e+07</td>\n",
       "      <td>8.144549e+06</td>\n",
       "      <td>5231370.586</td>\n",
       "      <td>9.675038e+06</td>\n",
       "      <td>1.214482e+07</td>\n",
       "      <td>13830000.0</td>\n",
       "      <td>6912484.62</td>\n",
       "      <td>6.532037e+06</td>\n",
       "      <td>8088000.0</td>\n",
       "      <td>8.263775e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-02</th>\n",
       "      <td>9.8920</td>\n",
       "      <td>5.3486</td>\n",
       "      <td>19.5469</td>\n",
       "      <td>32.6031</td>\n",
       "      <td>4.5931</td>\n",
       "      <td>7.5018</td>\n",
       "      <td>8.2821</td>\n",
       "      <td>15.4933</td>\n",
       "      <td>17.2487</td>\n",
       "      <td>12.8695</td>\n",
       "      <td>...</td>\n",
       "      <td>1.261396e+07</td>\n",
       "      <td>8.153598e+06</td>\n",
       "      <td>5178421.491</td>\n",
       "      <td>9.662713e+06</td>\n",
       "      <td>1.217288e+07</td>\n",
       "      <td>13415100.0</td>\n",
       "      <td>7162990.88</td>\n",
       "      <td>6.705759e+06</td>\n",
       "      <td>8035200.0</td>\n",
       "      <td>8.551555e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-03</th>\n",
       "      <td>9.8104</td>\n",
       "      <td>5.4729</td>\n",
       "      <td>19.4968</td>\n",
       "      <td>33.0956</td>\n",
       "      <td>4.5251</td>\n",
       "      <td>7.6364</td>\n",
       "      <td>8.2703</td>\n",
       "      <td>15.4064</td>\n",
       "      <td>16.8858</td>\n",
       "      <td>12.9481</td>\n",
       "      <td>...</td>\n",
       "      <td>1.274355e+07</td>\n",
       "      <td>8.186398e+06</td>\n",
       "      <td>5178421.491</td>\n",
       "      <td>9.684282e+06</td>\n",
       "      <td>1.194520e+07</td>\n",
       "      <td>13109918.0</td>\n",
       "      <td>7160510.62</td>\n",
       "      <td>6.518745e+06</td>\n",
       "      <td>8103360.0</td>\n",
       "      <td>8.570036e+06</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2875 rows × 1500 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "              pe_ttm                                                    \\\n",
       "ts_code    000001.SZ 000002.SZ 000063.SZ 000066.SZ 000069.SZ 000100.SZ   \n",
       "trade_date                                                               \n",
       "2010-01-04   78.7940   24.7229   40.8265   46.8105   52.3775   82.8030   \n",
       "2010-01-05   77.4315   24.1631   41.5908   49.3774   50.1030   85.3557   \n",
       "2010-01-06   76.1022   24.1631   40.7365   49.0313   50.6084   83.4412   \n",
       "2010-01-07   75.2714   23.9766   38.8571   48.9737   49.8502   82.8030   \n",
       "2010-01-08   75.1052   24.1398   39.0190   50.1562   50.3873   84.2389   \n",
       "...              ...       ...       ...       ...       ...       ...   \n",
       "2021-10-28   10.7300    5.5522   20.6761   33.8484    4.7971    7.3182   \n",
       "2021-10-29   10.6103    5.5214   20.4628   34.5156    4.7291    7.4161   \n",
       "2021-11-01   10.5504    5.5153   19.6912   32.9725    4.7291    7.7955   \n",
       "2021-11-02    9.8920    5.3486   19.5469   32.6031    4.5931    7.5018   \n",
       "2021-11-03    9.8104    5.4729   19.4968   33.0956    4.5251    7.6364   \n",
       "\n",
       "                                                    ...      total_mv  \\\n",
       "ts_code    000157.SZ 000166.SZ 000333.SZ 000338.SZ  ...     603993.SH   \n",
       "trade_date                                          ...                 \n",
       "2010-01-04   23.0347       NaN       NaN   23.0861  ...           NaN   \n",
       "2010-01-05   22.6384       NaN       NaN   22.6253  ...           NaN   \n",
       "2010-01-06   23.5392       NaN       NaN   24.6574  ...           NaN   \n",
       "2010-01-07   22.8816       NaN       NaN   24.6030  ...           NaN   \n",
       "2010-01-08   22.4672       NaN       NaN   24.9949  ...           NaN   \n",
       "...              ...       ...       ...       ...  ...           ...   \n",
       "2021-10-28    7.9264   15.6873   16.8023   11.9926  ...  1.285155e+07   \n",
       "2021-10-29    8.6129   15.5659   16.9626   12.0245  ...  1.293795e+07   \n",
       "2021-11-01    8.5775   15.4933   17.7359   13.1487  ...  1.295954e+07   \n",
       "2021-11-02    8.2821   15.4933   17.2487   12.8695  ...  1.261396e+07   \n",
       "2021-11-03    8.2703   15.4064   16.8858   12.9481  ...  1.274355e+07   \n",
       "\n",
       "                                                                               \\\n",
       "ts_code        688008.SH    688009.SH     688012.SH     688036.SH   688111.SH   \n",
       "trade_date                                                                      \n",
       "2010-01-04           NaN          NaN           NaN           NaN         NaN   \n",
       "2010-01-05           NaN          NaN           NaN           NaN         NaN   \n",
       "2010-01-06           NaN          NaN           NaN           NaN         NaN   \n",
       "2010-01-07           NaN          NaN           NaN           NaN         NaN   \n",
       "2010-01-08           NaN          NaN           NaN           NaN         NaN   \n",
       "...                  ...          ...           ...           ...         ...   \n",
       "2021-10-28  6.593907e+06  5220780.767  8.841260e+06  1.275490e+07  12098945.0   \n",
       "2021-10-29  7.363008e+06  5220780.767  9.625739e+06  1.266592e+07  13612408.0   \n",
       "2021-11-01  8.144549e+06  5231370.586  9.675038e+06  1.214482e+07  13830000.0   \n",
       "2021-11-02  8.153598e+06  5178421.491  9.662713e+06  1.217288e+07  13415100.0   \n",
       "2021-11-03  8.186398e+06  5178421.491  9.684282e+06  1.194520e+07  13109918.0   \n",
       "\n",
       "                                                               \n",
       "ts_code      688126.SH     688169.SH  688363.SH     688396.SH  \n",
       "trade_date                                                     \n",
       "2010-01-04         NaN           NaN        NaN           NaN  \n",
       "2010-01-05         NaN           NaN        NaN           NaN  \n",
       "2010-01-06         NaN           NaN        NaN           NaN  \n",
       "2010-01-07         NaN           NaN        NaN           NaN  \n",
       "2010-01-08         NaN           NaN        NaN           NaN  \n",
       "...                ...           ...        ...           ...  \n",
       "2021-10-28  6870320.20  5.877691e+06  7615680.0  7.928472e+06  \n",
       "2021-10-29  6996813.46  6.011138e+06  7968000.0  8.155528e+06  \n",
       "2021-11-01  6912484.62  6.532037e+06  8088000.0  8.263775e+06  \n",
       "2021-11-02  7162990.88  6.705759e+06  8035200.0  8.551555e+06  \n",
       "2021-11-03  7160510.62  6.518745e+06  8103360.0  8.570036e+06  \n",
       "\n",
       "[2875 rows x 1500 columns]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dd_dailybasic.pivot(index='trade_date',columns='ts_code',values=['pe_ttm','pb','turnover_rate_f','dv_ttm','total_mv'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "bb00d291",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>index</th>\n",
       "      <th>ts_code</th>\n",
       "      <th>trade_date</th>\n",
       "      <th>close</th>\n",
       "      <th>turnover_rate</th>\n",
       "      <th>turnover_rate_f</th>\n",
       "      <th>volume_ratio</th>\n",
       "      <th>pe</th>\n",
       "      <th>pe_ttm</th>\n",
       "      <th>pb</th>\n",
       "      <th>ps</th>\n",
       "      <th>ps_ttm</th>\n",
       "      <th>dv_ratio</th>\n",
       "      <th>dv_ttm</th>\n",
       "      <th>total_share</th>\n",
       "      <th>float_share</th>\n",
       "      <th>free_share</th>\n",
       "      <th>total_mv</th>\n",
       "      <th>circ_mv</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>4</td>\n",
       "      <td>300033.SZ</td>\n",
       "      <td>2010-01-04</td>\n",
       "      <td>74.57</td>\n",
       "      <td>26.9897</td>\n",
       "      <td>26.9897</td>\n",
       "      <td>1.04</td>\n",
       "      <td>130.6829</td>\n",
       "      <td>89.4577</td>\n",
       "      <td>5.0529</td>\n",
       "      <td>42.6980</td>\n",
       "      <td>31.4715</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6.720000e+03</td>\n",
       "      <td>1.344000e+03</td>\n",
       "      <td>1344.0000</td>\n",
       "      <td>5.011104e+05</td>\n",
       "      <td>1.002221e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>14</td>\n",
       "      <td>002311.SZ</td>\n",
       "      <td>2010-01-04</td>\n",
       "      <td>37.52</td>\n",
       "      <td>9.5987</td>\n",
       "      <td>9.5987</td>\n",
       "      <td>1.17</td>\n",
       "      <td>64.3319</td>\n",
       "      <td>50.9642</td>\n",
       "      <td>4.1181</td>\n",
       "      <td>1.8552</td>\n",
       "      <td>1.6763</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.240000e+04</td>\n",
       "      <td>4.480000e+03</td>\n",
       "      <td>4480.0000</td>\n",
       "      <td>8.404480e+05</td>\n",
       "      <td>1.680896e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>33</td>\n",
       "      <td>600999.SH</td>\n",
       "      <td>2010-01-04</td>\n",
       "      <td>29.21</td>\n",
       "      <td>2.9856</td>\n",
       "      <td>2.9856</td>\n",
       "      <td>0.91</td>\n",
       "      <td>51.8293</td>\n",
       "      <td>48.2327</td>\n",
       "      <td>5.1887</td>\n",
       "      <td>21.2996</td>\n",
       "      <td>19.4665</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3.585461e+05</td>\n",
       "      <td>2.868370e+04</td>\n",
       "      <td>28683.7000</td>\n",
       "      <td>1.047313e+07</td>\n",
       "      <td>8.378509e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>38</td>\n",
       "      <td>601006.SH</td>\n",
       "      <td>2010-01-04</td>\n",
       "      <td>10.21</td>\n",
       "      <td>0.2785</td>\n",
       "      <td>0.9499</td>\n",
       "      <td>0.67</td>\n",
       "      <td>19.8357</td>\n",
       "      <td>23.2114</td>\n",
       "      <td>3.2297</td>\n",
       "      <td>5.8637</td>\n",
       "      <td>6.2674</td>\n",
       "      <td>2.9383</td>\n",
       "      <td>2.9383</td>\n",
       "      <td>1.297676e+06</td>\n",
       "      <td>1.297676e+06</td>\n",
       "      <td>380466.3591</td>\n",
       "      <td>1.324927e+07</td>\n",
       "      <td>1.324927e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>47</td>\n",
       "      <td>600000.SH</td>\n",
       "      <td>2010-01-04</td>\n",
       "      <td>21.19</td>\n",
       "      <td>0.8351</td>\n",
       "      <td>1.2591</td>\n",
       "      <td>0.94</td>\n",
       "      <td>14.9496</td>\n",
       "      <td>14.4351</td>\n",
       "      <td>2.8771</td>\n",
       "      <td>5.4139</td>\n",
       "      <td>5.3163</td>\n",
       "      <td>0.7000</td>\n",
       "      <td>0.7000</td>\n",
       "      <td>8.830046e+05</td>\n",
       "      <td>7.925887e+05</td>\n",
       "      <td>525692.8099</td>\n",
       "      <td>1.871087e+07</td>\n",
       "      <td>1.679495e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>672323</th>\n",
       "      <td>4437</td>\n",
       "      <td>601788.SH</td>\n",
       "      <td>2021-11-03</td>\n",
       "      <td>14.87</td>\n",
       "      <td>0.5140</td>\n",
       "      <td>1.1239</td>\n",
       "      <td>0.88</td>\n",
       "      <td>29.3745</td>\n",
       "      <td>30.0546</td>\n",
       "      <td>1.3031</td>\n",
       "      <td>4.3212</td>\n",
       "      <td>3.9177</td>\n",
       "      <td>0.2488</td>\n",
       "      <td>1.0625</td>\n",
       "      <td>4.610788e+05</td>\n",
       "      <td>3.906699e+05</td>\n",
       "      <td>178677.5656</td>\n",
       "      <td>6.856241e+06</td>\n",
       "      <td>5.809261e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>672324</th>\n",
       "      <td>4459</td>\n",
       "      <td>600030.SH</td>\n",
       "      <td>2021-11-03</td>\n",
       "      <td>25.39</td>\n",
       "      <td>0.5811</td>\n",
       "      <td>0.7297</td>\n",
       "      <td>0.57</td>\n",
       "      <td>22.0241</td>\n",
       "      <td>16.5041</td>\n",
       "      <td>1.6996</td>\n",
       "      <td>6.0352</td>\n",
       "      <td>4.6754</td>\n",
       "      <td>1.9693</td>\n",
       "      <td>1.5754</td>\n",
       "      <td>1.292678e+06</td>\n",
       "      <td>9.814662e+05</td>\n",
       "      <td>781496.5954</td>\n",
       "      <td>3.282108e+07</td>\n",
       "      <td>2.491943e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>672325</th>\n",
       "      <td>4469</td>\n",
       "      <td>002736.SZ</td>\n",
       "      <td>2021-11-03</td>\n",
       "      <td>11.19</td>\n",
       "      <td>0.1618</td>\n",
       "      <td>0.5197</td>\n",
       "      <td>0.83</td>\n",
       "      <td>16.2587</td>\n",
       "      <td>12.0298</td>\n",
       "      <td>1.4427</td>\n",
       "      <td>5.7263</td>\n",
       "      <td>4.9385</td>\n",
       "      <td>1.5247</td>\n",
       "      <td>2.0554</td>\n",
       "      <td>9.612429e+05</td>\n",
       "      <td>8.827119e+05</td>\n",
       "      <td>274886.1813</td>\n",
       "      <td>1.075631e+07</td>\n",
       "      <td>9.877546e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>672326</th>\n",
       "      <td>4489</td>\n",
       "      <td>601698.SH</td>\n",
       "      <td>2021-11-03</td>\n",
       "      <td>14.05</td>\n",
       "      <td>1.6779</td>\n",
       "      <td>1.6779</td>\n",
       "      <td>0.90</td>\n",
       "      <td>114.9780</td>\n",
       "      <td>106.6995</td>\n",
       "      <td>4.7652</td>\n",
       "      <td>20.7357</td>\n",
       "      <td>21.1958</td>\n",
       "      <td>0.1637</td>\n",
       "      <td>0.2562</td>\n",
       "      <td>4.000000e+05</td>\n",
       "      <td>4.076375e+04</td>\n",
       "      <td>40763.7548</td>\n",
       "      <td>5.620000e+06</td>\n",
       "      <td>5.727308e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>672327</th>\n",
       "      <td>4509</td>\n",
       "      <td>002558.SZ</td>\n",
       "      <td>2021-11-03</td>\n",
       "      <td>10.09</td>\n",
       "      <td>0.4620</td>\n",
       "      <td>0.9813</td>\n",
       "      <td>0.90</td>\n",
       "      <td>19.8502</td>\n",
       "      <td>19.1668</td>\n",
       "      <td>1.9310</td>\n",
       "      <td>9.2121</td>\n",
       "      <td>10.0372</td>\n",
       "      <td>1.2217</td>\n",
       "      <td>1.5314</td>\n",
       "      <td>2.024380e+05</td>\n",
       "      <td>2.024380e+05</td>\n",
       "      <td>95308.8284</td>\n",
       "      <td>2.042599e+06</td>\n",
       "      <td>2.042599e+06</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>672328 rows × 19 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        index    ts_code trade_date  close  turnover_rate  turnover_rate_f  \\\n",
       "0           4  300033.SZ 2010-01-04  74.57        26.9897          26.9897   \n",
       "1          14  002311.SZ 2010-01-04  37.52         9.5987           9.5987   \n",
       "2          33  600999.SH 2010-01-04  29.21         2.9856           2.9856   \n",
       "3          38  601006.SH 2010-01-04  10.21         0.2785           0.9499   \n",
       "4          47  600000.SH 2010-01-04  21.19         0.8351           1.2591   \n",
       "...       ...        ...        ...    ...            ...              ...   \n",
       "672323   4437  601788.SH 2021-11-03  14.87         0.5140           1.1239   \n",
       "672324   4459  600030.SH 2021-11-03  25.39         0.5811           0.7297   \n",
       "672325   4469  002736.SZ 2021-11-03  11.19         0.1618           0.5197   \n",
       "672326   4489  601698.SH 2021-11-03  14.05         1.6779           1.6779   \n",
       "672327   4509  002558.SZ 2021-11-03  10.09         0.4620           0.9813   \n",
       "\n",
       "        volume_ratio        pe    pe_ttm      pb       ps   ps_ttm  dv_ratio  \\\n",
       "0               1.04  130.6829   89.4577  5.0529  42.6980  31.4715       NaN   \n",
       "1               1.17   64.3319   50.9642  4.1181   1.8552   1.6763       NaN   \n",
       "2               0.91   51.8293   48.2327  5.1887  21.2996  19.4665       NaN   \n",
       "3               0.67   19.8357   23.2114  3.2297   5.8637   6.2674    2.9383   \n",
       "4               0.94   14.9496   14.4351  2.8771   5.4139   5.3163    0.7000   \n",
       "...              ...       ...       ...     ...      ...      ...       ...   \n",
       "672323          0.88   29.3745   30.0546  1.3031   4.3212   3.9177    0.2488   \n",
       "672324          0.57   22.0241   16.5041  1.6996   6.0352   4.6754    1.9693   \n",
       "672325          0.83   16.2587   12.0298  1.4427   5.7263   4.9385    1.5247   \n",
       "672326          0.90  114.9780  106.6995  4.7652  20.7357  21.1958    0.1637   \n",
       "672327          0.90   19.8502   19.1668  1.9310   9.2121  10.0372    1.2217   \n",
       "\n",
       "        dv_ttm   total_share   float_share   free_share      total_mv  \\\n",
       "0          NaN  6.720000e+03  1.344000e+03    1344.0000  5.011104e+05   \n",
       "1          NaN  2.240000e+04  4.480000e+03    4480.0000  8.404480e+05   \n",
       "2          NaN  3.585461e+05  2.868370e+04   28683.7000  1.047313e+07   \n",
       "3       2.9383  1.297676e+06  1.297676e+06  380466.3591  1.324927e+07   \n",
       "4       0.7000  8.830046e+05  7.925887e+05  525692.8099  1.871087e+07   \n",
       "...        ...           ...           ...          ...           ...   \n",
       "672323  1.0625  4.610788e+05  3.906699e+05  178677.5656  6.856241e+06   \n",
       "672324  1.5754  1.292678e+06  9.814662e+05  781496.5954  3.282108e+07   \n",
       "672325  2.0554  9.612429e+05  8.827119e+05  274886.1813  1.075631e+07   \n",
       "672326  0.2562  4.000000e+05  4.076375e+04   40763.7548  5.620000e+06   \n",
       "672327  1.5314  2.024380e+05  2.024380e+05   95308.8284  2.042599e+06   \n",
       "\n",
       "             circ_mv  \n",
       "0       1.002221e+05  \n",
       "1       1.680896e+05  \n",
       "2       8.378509e+05  \n",
       "3       1.324927e+07  \n",
       "4       1.679495e+07  \n",
       "...              ...  \n",
       "672323  5.809261e+06  \n",
       "672324  2.491943e+07  \n",
       "672325  9.877546e+06  \n",
       "672326  5.727308e+05  \n",
       "672327  2.042599e+06  \n",
       "\n",
       "[672328 rows x 19 columns]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dd_dailybasic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eabc07f0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "3df18cd6",
   "metadata": {},
   "outputs": [],
   "source": [
    "dd_pettm = dd_dailybasic.pivot(index='trade_date',columns='ts_code',values=['pe_ttm'])\n",
    "cols = list(map(lambda x:x[1],dd_pettm.columns))\n",
    "dd_pettm.columns = cols\n",
    "\n",
    "dd_pb = dd_dailybasic.pivot(index='trade_date',columns='ts_code',values=['pb'])\n",
    "cols = list(map(lambda x:x[1],dd_pb.columns))\n",
    "dd_pb.columns = cols"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "91cd02a0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>000001.SZ</th>\n",
       "      <th>000002.SZ</th>\n",
       "      <th>000063.SZ</th>\n",
       "      <th>000066.SZ</th>\n",
       "      <th>000069.SZ</th>\n",
       "      <th>000100.SZ</th>\n",
       "      <th>000157.SZ</th>\n",
       "      <th>000166.SZ</th>\n",
       "      <th>000333.SZ</th>\n",
       "      <th>000338.SZ</th>\n",
       "      <th>...</th>\n",
       "      <th>603993.SH</th>\n",
       "      <th>688008.SH</th>\n",
       "      <th>688009.SH</th>\n",
       "      <th>688012.SH</th>\n",
       "      <th>688036.SH</th>\n",
       "      <th>688111.SH</th>\n",
       "      <th>688126.SH</th>\n",
       "      <th>688169.SH</th>\n",
       "      <th>688363.SH</th>\n",
       "      <th>688396.SH</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>trade_date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2010-01-04</th>\n",
       "      <td>78.7940</td>\n",
       "      <td>24.7229</td>\n",
       "      <td>40.8265</td>\n",
       "      <td>46.8105</td>\n",
       "      <td>52.3775</td>\n",
       "      <td>82.8030</td>\n",
       "      <td>23.0347</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>23.0861</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-05</th>\n",
       "      <td>77.4315</td>\n",
       "      <td>24.1631</td>\n",
       "      <td>41.5908</td>\n",
       "      <td>49.3774</td>\n",
       "      <td>50.1030</td>\n",
       "      <td>85.3557</td>\n",
       "      <td>22.6384</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>22.6253</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-06</th>\n",
       "      <td>76.1022</td>\n",
       "      <td>24.1631</td>\n",
       "      <td>40.7365</td>\n",
       "      <td>49.0313</td>\n",
       "      <td>50.6084</td>\n",
       "      <td>83.4412</td>\n",
       "      <td>23.5392</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>24.6574</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-07</th>\n",
       "      <td>75.2714</td>\n",
       "      <td>23.9766</td>\n",
       "      <td>38.8571</td>\n",
       "      <td>48.9737</td>\n",
       "      <td>49.8502</td>\n",
       "      <td>82.8030</td>\n",
       "      <td>22.8816</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>24.6030</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-01-08</th>\n",
       "      <td>75.1052</td>\n",
       "      <td>24.1398</td>\n",
       "      <td>39.0190</td>\n",
       "      <td>50.1562</td>\n",
       "      <td>50.3873</td>\n",
       "      <td>84.2389</td>\n",
       "      <td>22.4672</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>24.9949</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-10-28</th>\n",
       "      <td>10.7300</td>\n",
       "      <td>5.5522</td>\n",
       "      <td>20.6761</td>\n",
       "      <td>33.8484</td>\n",
       "      <td>4.7971</td>\n",
       "      <td>7.3182</td>\n",
       "      <td>7.9264</td>\n",
       "      <td>15.6873</td>\n",
       "      <td>16.8023</td>\n",
       "      <td>11.9926</td>\n",
       "      <td>...</td>\n",
       "      <td>30.0449</td>\n",
       "      <td>81.4057</td>\n",
       "      <td>14.5990</td>\n",
       "      <td>116.7749</td>\n",
       "      <td>35.2898</td>\n",
       "      <td>113.1264</td>\n",
       "      <td>249.8692</td>\n",
       "      <td>37.6587</td>\n",
       "      <td>99.7371</td>\n",
       "      <td>40.4374</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-10-29</th>\n",
       "      <td>10.6103</td>\n",
       "      <td>5.5214</td>\n",
       "      <td>20.4628</td>\n",
       "      <td>34.5156</td>\n",
       "      <td>4.7291</td>\n",
       "      <td>7.4161</td>\n",
       "      <td>8.6129</td>\n",
       "      <td>15.5659</td>\n",
       "      <td>16.9626</td>\n",
       "      <td>12.0245</td>\n",
       "      <td>...</td>\n",
       "      <td>30.2469</td>\n",
       "      <td>99.7204</td>\n",
       "      <td>14.5990</td>\n",
       "      <td>127.1362</td>\n",
       "      <td>35.0436</td>\n",
       "      <td>120.3832</td>\n",
       "      <td>369.2888</td>\n",
       "      <td>38.5137</td>\n",
       "      <td>104.3511</td>\n",
       "      <td>41.5954</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-01</th>\n",
       "      <td>10.5504</td>\n",
       "      <td>5.5153</td>\n",
       "      <td>19.6912</td>\n",
       "      <td>32.9725</td>\n",
       "      <td>4.7291</td>\n",
       "      <td>7.7955</td>\n",
       "      <td>8.5775</td>\n",
       "      <td>15.4933</td>\n",
       "      <td>17.7359</td>\n",
       "      <td>13.1487</td>\n",
       "      <td>...</td>\n",
       "      <td>30.2974</td>\n",
       "      <td>110.3052</td>\n",
       "      <td>14.6286</td>\n",
       "      <td>127.7874</td>\n",
       "      <td>33.6018</td>\n",
       "      <td>122.3075</td>\n",
       "      <td>364.8379</td>\n",
       "      <td>43.9533</td>\n",
       "      <td>105.9227</td>\n",
       "      <td>42.1475</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-02</th>\n",
       "      <td>9.8920</td>\n",
       "      <td>5.3486</td>\n",
       "      <td>19.5469</td>\n",
       "      <td>32.6031</td>\n",
       "      <td>4.5931</td>\n",
       "      <td>7.5018</td>\n",
       "      <td>8.2821</td>\n",
       "      <td>15.4933</td>\n",
       "      <td>17.2487</td>\n",
       "      <td>12.8695</td>\n",
       "      <td>...</td>\n",
       "      <td>29.4895</td>\n",
       "      <td>110.4277</td>\n",
       "      <td>14.4806</td>\n",
       "      <td>127.6246</td>\n",
       "      <td>33.6795</td>\n",
       "      <td>118.6383</td>\n",
       "      <td>378.0595</td>\n",
       "      <td>45.1223</td>\n",
       "      <td>105.2312</td>\n",
       "      <td>43.6152</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-11-03</th>\n",
       "      <td>9.8104</td>\n",
       "      <td>5.4729</td>\n",
       "      <td>19.4968</td>\n",
       "      <td>33.0956</td>\n",
       "      <td>4.5251</td>\n",
       "      <td>7.6364</td>\n",
       "      <td>8.2703</td>\n",
       "      <td>15.4064</td>\n",
       "      <td>16.8858</td>\n",
       "      <td>12.9481</td>\n",
       "      <td>...</td>\n",
       "      <td>29.7925</td>\n",
       "      <td>110.8720</td>\n",
       "      <td>14.4806</td>\n",
       "      <td>127.9095</td>\n",
       "      <td>33.0495</td>\n",
       "      <td>115.9394</td>\n",
       "      <td>377.9286</td>\n",
       "      <td>43.8639</td>\n",
       "      <td>106.1239</td>\n",
       "      <td>43.7095</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2875 rows × 300 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            000001.SZ  000002.SZ  000063.SZ  000066.SZ  000069.SZ  000100.SZ  \\\n",
       "trade_date                                                                     \n",
       "2010-01-04    78.7940    24.7229    40.8265    46.8105    52.3775    82.8030   \n",
       "2010-01-05    77.4315    24.1631    41.5908    49.3774    50.1030    85.3557   \n",
       "2010-01-06    76.1022    24.1631    40.7365    49.0313    50.6084    83.4412   \n",
       "2010-01-07    75.2714    23.9766    38.8571    48.9737    49.8502    82.8030   \n",
       "2010-01-08    75.1052    24.1398    39.0190    50.1562    50.3873    84.2389   \n",
       "...               ...        ...        ...        ...        ...        ...   \n",
       "2021-10-28    10.7300     5.5522    20.6761    33.8484     4.7971     7.3182   \n",
       "2021-10-29    10.6103     5.5214    20.4628    34.5156     4.7291     7.4161   \n",
       "2021-11-01    10.5504     5.5153    19.6912    32.9725     4.7291     7.7955   \n",
       "2021-11-02     9.8920     5.3486    19.5469    32.6031     4.5931     7.5018   \n",
       "2021-11-03     9.8104     5.4729    19.4968    33.0956     4.5251     7.6364   \n",
       "\n",
       "            000157.SZ  000166.SZ  000333.SZ  000338.SZ  ...  603993.SH  \\\n",
       "trade_date                                              ...              \n",
       "2010-01-04    23.0347        NaN        NaN    23.0861  ...        NaN   \n",
       "2010-01-05    22.6384        NaN        NaN    22.6253  ...        NaN   \n",
       "2010-01-06    23.5392        NaN        NaN    24.6574  ...        NaN   \n",
       "2010-01-07    22.8816        NaN        NaN    24.6030  ...        NaN   \n",
       "2010-01-08    22.4672        NaN        NaN    24.9949  ...        NaN   \n",
       "...               ...        ...        ...        ...  ...        ...   \n",
       "2021-10-28     7.9264    15.6873    16.8023    11.9926  ...    30.0449   \n",
       "2021-10-29     8.6129    15.5659    16.9626    12.0245  ...    30.2469   \n",
       "2021-11-01     8.5775    15.4933    17.7359    13.1487  ...    30.2974   \n",
       "2021-11-02     8.2821    15.4933    17.2487    12.8695  ...    29.4895   \n",
       "2021-11-03     8.2703    15.4064    16.8858    12.9481  ...    29.7925   \n",
       "\n",
       "            688008.SH  688009.SH  688012.SH  688036.SH  688111.SH  688126.SH  \\\n",
       "trade_date                                                                     \n",
       "2010-01-04        NaN        NaN        NaN        NaN        NaN        NaN   \n",
       "2010-01-05        NaN        NaN        NaN        NaN        NaN        NaN   \n",
       "2010-01-06        NaN        NaN        NaN        NaN        NaN        NaN   \n",
       "2010-01-07        NaN        NaN        NaN        NaN        NaN        NaN   \n",
       "2010-01-08        NaN        NaN        NaN        NaN        NaN        NaN   \n",
       "...               ...        ...        ...        ...        ...        ...   \n",
       "2021-10-28    81.4057    14.5990   116.7749    35.2898   113.1264   249.8692   \n",
       "2021-10-29    99.7204    14.5990   127.1362    35.0436   120.3832   369.2888   \n",
       "2021-11-01   110.3052    14.6286   127.7874    33.6018   122.3075   364.8379   \n",
       "2021-11-02   110.4277    14.4806   127.6246    33.6795   118.6383   378.0595   \n",
       "2021-11-03   110.8720    14.4806   127.9095    33.0495   115.9394   377.9286   \n",
       "\n",
       "            688169.SH  688363.SH  688396.SH  \n",
       "trade_date                                   \n",
       "2010-01-04        NaN        NaN        NaN  \n",
       "2010-01-05        NaN        NaN        NaN  \n",
       "2010-01-06        NaN        NaN        NaN  \n",
       "2010-01-07        NaN        NaN        NaN  \n",
       "2010-01-08        NaN        NaN        NaN  \n",
       "...               ...        ...        ...  \n",
       "2021-10-28    37.6587    99.7371    40.4374  \n",
       "2021-10-29    38.5137   104.3511    41.5954  \n",
       "2021-11-01    43.9533   105.9227    42.1475  \n",
       "2021-11-02    45.1223   105.2312    43.6152  \n",
       "2021-11-03    43.8639   106.1239    43.7095  \n",
       "\n",
       "[2875 rows x 300 columns]"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dd_pettm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fbd61abe",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
